﻿using App.IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using App.Entity;
using App.IRepository;
using App.Code;

namespace App.Services
{
    public class DutyServices : IDutyServices
    {
        ISys_RoleRepository _ISys_RoleRepository;
        public DutyServices(ISys_RoleRepository __ISys_RoleRepository) {
            this._ISys_RoleRepository = __ISys_RoleRepository;
        }
        public void DeleteForm(string keyValue)
        {
            _ISys_RoleRepository.Delete(t => t.Id == keyValue);
        }

        public Sys_Role GetForm(string keyValue)
        {
            return _ISys_RoleRepository.QuerySingle(c => c.Id == keyValue);
        }

        public List<Sys_Role> GetList(string keyword = "")
        {
            var expression = ExtLinq.True<Sys_Role>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.FullName.Contains(keyword));
                expression = expression.Or(t => t.EnCode.Contains(keyword));
            }
            expression = expression.And(t => t.Category == 2);
            return _ISys_RoleRepository.QueryByWhere(expression, "SortCode");
           
        }

        public void SubmitForm(Sys_Role roleEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                roleEntity.Modify(keyValue);
                _ISys_RoleRepository.Update(roleEntity);
            }
            else
            {
                roleEntity.Create();
                roleEntity.Category = 2;
                _ISys_RoleRepository.Insert(roleEntity);
            }
        }
    }
}
